package com.zkh.myutils.io.excel.worksheet.style;

import java.util.Objects;

import com.zkh.myutils.utils.Assert;

/**
 * 单元格边框相关属性，在样式文件中呈现方式为borders节点的子节点
 * @author zkh
 */
public class Border {
	//边框（加粗、颜色）
	private BorderStyle top;
	private BorderStyle right;
	private BorderStyle bottom;
	private BorderStyle left;
	
	/**
	 * 构造方法
	 */
	public Border() {}
	
	/**
	 * 构造方法，对上下左右边框同时设置相同样式
	 * @param borderStyle 边框样式
	 */
	public Border(BorderStyle borderStyle) {
		setBorder(borderStyle);
	}
	
	/**
	 * 构造方法，对上、右、下、左边框同时设置样式
	 * @param top 上边框样式
	 * @param right 右边框样式
	 * @param bottom 下边框样式
	 * @param left 左边框样式
	 */
	public Border(BorderStyle top, BorderStyle right, BorderStyle bottom, BorderStyle left) {
		this.top = top;
		this.right = right;
		this.bottom = bottom;
		this.left = left;
	}
	
	/**
	 * 设置顶部边框样式
	 * @param topStyle 边框样式
	 */
	public void setBorderTop(BorderStyle topStyle) {
		this.top = topStyle;
	}
	/**
	 * 设置右边边框样式
	 * @param rightStyle 边框样式
	 */
	public void setBorderRight(BorderStyle rightStyle) {
		this.right = rightStyle;
	}
	/**
	 * 设置底部边框样式
	 * @param bottomStyle 边框样式
	 */
	public void setBorderBottom(BorderStyle bottomStyle) {
		this.bottom = bottomStyle;
	}
	/**
	 * 设置左边边框样式
	 * @param leftStyle 边框样式
	 */
	public void setBorderLeft(BorderStyle leftStyle) {
		this.left = leftStyle;
	}
	
	/**
	 * 同时设置四边边框样式
	 * @param borderStyle 边框样式
	 */
	public void setBorder(BorderStyle borderStyle) {
		this.top = borderStyle;
		this.right = borderStyle;
		this.bottom = borderStyle;
		this.left = borderStyle;
	}

	/**
	 * 获取上边框样式
	 */
	public BorderStyle getTop() {
		return top;
	}

	/**
	 * 获取右边框样式
	 */
	public BorderStyle getRight() {
		return right;
	}

	/**
	 * 获取下边框样式
	 */
	public BorderStyle getBottom() {
		return bottom;
	}

	/**
	 * 获取左边框样式
	 */
	public BorderStyle getLeft() {
		return left;
	}

	@Override
	public int hashCode() {
		return Objects.hash(bottom, left, right, top);
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Border other = (Border) obj;
		return Objects.equals(bottom, other.bottom)
				&& Objects.equals(left, other.left)
				&& Objects.equals(right, other.right)
				&& Objects.equals(top, other.top);
	}
	
	/**
	 * 判断为空
	 */
	public boolean isEmpty() {
		return top==null && right==null && bottom==null && left==null;
	}
	
	public Border clone() {
		//创建新对象
		Border border = new Border();
		//复制值
		Assert.doIfNotNull(top, bd->border.setBorderTop(bd.clone()));
		Assert.doIfNotNull(right, bd->border.setBorderRight(bd.clone()));
		Assert.doIfNotNull(bottom, bd->border.setBorderBottom(bd.clone()));
		Assert.doIfNotNull(left, bd->border.setBorderLeft(bd.clone()));
		//返回
		return border;
	}
}
